﻿@using SmartStore.Core.Domain.Catalog;
@using SmartStore.Web.Framework.UI;
@model ProductModel
@{
	Html.AddCssFileParts(true, "~/Content/vendors/x-editable/bootstrap-editable.css");
	Html.AppendScriptParts(true, "~/Content/vendors/x-editable/bootstrap-editable.js");
}

@Html.ValidationSummary(false)
@Html.HiddenFor(model => model.Id)

<script>
	function productEditTab_onAjaxSuccess(tab, pane) {
		applyCommonPlugins(pane);
	}
</script>

@Html.SmartStore().TabStrip().Name("product-edit").OnAjaxSuccess("productEditTab_onAjaxSuccess").HtmlAttributes(new { data_product_id = Model.Id }).Style(TabsStyle.Material).Position(TabsPosition.Left).Items(x =>
{
    x.Add().Text(T("Admin.Catalog.Products.Info"))
        .Icon("fa fa-pencil-alt fa-lg fa-fw")
        .LinkHtmlAttributes(new { data_tab_name = "Info" })
        .Content(Html.Partial("_CreateOrUpdate.Info", Model).ToHtmlString())
        .Selected(true);

    x.Add().Text(T("Admin.Catalog.Products.Inventory").Text)
        .Name("tab-inventory")
        .Visible(Model.ProductTypeId == (int)ProductType.SimpleProduct || (Model.ProductTypeId == (int)ProductType.BundledProduct && !Model.BundlePerItemShoppingCart))
        .Icon("fa fa-archive fa-lg fa-fw")
        .LinkHtmlAttributes(new { data_tab_name = "Inventory" })
        .Action("LoadEditTab", "Product", new { id = Model.Id, tabName = "Inventory" })
        .Ajax();

    if (Model.Id > 0)
    {
        if (Model.ProductTypeId == (int)ProductType.GroupedProduct)
        {
            x.Add().Text(T("Admin.Catalog.Products.AssociatedProducts").Text)
                .Icon("fa fa-link fa-lg fa-fw")
                .LinkHtmlAttributes(new { data_tab_name = "AssociatedProducts" })
                .Action("LoadEditTab", "Product", new { id = Model.Id, tabName = "AssociatedProducts" })
                .Ajax();
        }
        else if (Model.ProductTypeId == (int)ProductType.BundledProduct)
        {
            x.Add().Text(T("Admin.Catalog.Products.BundleItems").Text)
                .Icon("fa fa-link fa-lg fa-fw")
                .LinkHtmlAttributes(new { data_tab_name = "BundleItems" })
                .Action("LoadEditTab", "Product", new { id = Model.Id, tabName = "BundleItems" })
                .Ajax();
        }
    }

    if (Model.ProductTypeId != (int)ProductType.GroupedProduct)
    {
        x.Add().Text(T("Admin.Catalog.Products.Price").Text)
            .Icon("fa fa-euro-sign fa-lg fa-fw")
            .LinkHtmlAttributes(new { data_tab_name = "Price" })
            .Action("LoadEditTab", "Product", new { id = Model.Id, tabName = "Price" })
            .Ajax();
    }

    x.Add().Text(T("Admin.Catalog.Products.Discounts").Text)
        .Name("tab-discounts")
        .Visible(!(Model.ProductTypeId == (int)ProductType.BundledProduct && Model.BundlePerItemPricing))
        .Icon("fa fa-percent fa-lg fa-fw")
        .LinkHtmlAttributes(new { data_tab_name = "Discounts" })
        .Action("LoadEditTab", "Product", new { id = Model.Id, tabName = "Discounts" })
        .Ajax();
    x.Add().Text(T("Admin.Catalog.Products.Pictures").Text)
        .Icon("far fa-image fa-lg fa-fw")
        .LinkHtmlAttributes(new { data_tab_name = "Pictures" })
        .Action("LoadEditTab", "Product", new { id = Model.Id, tabName = "Pictures" })
        .Ajax();
    x.Add().Text(T("Admin.Catalog.Products.Categories").Text)
        .Icon("fa fa-sitemap fa-lg fa-fw")
        .LinkHtmlAttributes(new { data_tab_name = "Categories" })
        .Action("LoadEditTab", "Product", new { id = Model.Id, tabName = "Categories" })
        .Ajax();
    x.Add().Text(T("Admin.Catalog.Products.Manufacturers").Text)
        .Icon("far fa-building fa-lg fa-fw")
        .LinkHtmlAttributes(new { data_tab_name = "Manufacturers" })
        .Action("LoadEditTab", "Product", new { id = Model.Id, tabName = "Manufacturers" })
        .Ajax();
    x.Add().Text(T("Admin.Catalog.Products.Promotion").Text)
        .Icon("fa fa-bullhorn fa-lg fa-fw")
        .LinkHtmlAttributes(new { data_tab_name = "Promotion" })
        .Action("LoadEditTab", "Product", new { id = Model.Id, tabName = "Promotion" })
        .Ajax();

    if (Model.ProductTypeId != (int)ProductType.BundledProduct)
    {
        x.Add().Text(T("Admin.Catalog.Products.ProductVariantAttributes.Attributes").Text)
            .Icon("far fa-list-alt fa-lg fa-fw")
            .LinkHtmlAttributes(new { data_tab_name = "Attributes" })
            .Action("LoadEditTab", "Product", new { id = Model.Id, tabName = "Attributes" })
            .Ajax();
    }

    x.Add().Text(T("Admin.Catalog.Products.SpecificationAttributes").Text)
        .Icon("fa fa-bars fa-lg fa-fw")
        .LinkHtmlAttributes(new { data_tab_name = "SpecificationAttributes" })
        .Action("LoadEditTab", "Product", new { id = Model.Id, tabName = "SpecificationAttributes" })
        .Ajax();
    x.Add().Text(T("Admin.Common.SEO").Text)
        .Icon("fa fa-search fa-lg fa-fw")
        .LinkHtmlAttributes(new { data_tab_name = "SEO" })
        .Content(Html.Partial("_CreateOrUpdate.SEO", Model).ToHtmlString());
    x.Add().Text(T("Admin.Catalog.Products.Acl").Text)
        .Icon("fa fa-users fa-lg fa-fw")
        .LinkHtmlAttributes(new { data_tab_name = "Acl" })
        .Action("LoadEditTab", "Product", new { id = Model.Id, tabName = "Acl" })
        .Ajax();
    x.Add().Text(T("Admin.Common.Stores").Text)
        .Icon("fa fa-globe fa-lg fa-fw")
        .LinkHtmlAttributes(new { data_tab_name = "Stores" })
        .Action("LoadEditTab", "Product", new { id = Model.Id, tabName = "Stores" })
        .Ajax();
    x.Add().Text(T("Common.Downloads").Text)
        .Icon("fa fa-download fa-lg fa-fw")
        .LinkHtmlAttributes(new { data_tab_name = "Downloads" })
        .Content(Html.Partial("_CreateOrUpdate.Downloads", Model).ToHtmlString());

    // generate an event
    EngineContext.Current.Resolve<IEventPublisher>().Publish(new TabStripCreated(x, "product-edit", this.Html, this.Model));
})

